<?php
/**
 * Created by PhpStorm.
 * User: 王世鹏
 * Date: 2018/3/6
 * Time: 19:34
 */

namespace app\index\controller;


use think\Db;

class Test
{
    public function add()
    {
        //1
//        $data = input("get.");
//        $result = Db::execute('INSERT INTO goods(price,name,count,type)VALUES(:price,:name,:count,:type)',$data);
//        return $result;
        //2
        $data = input("get.");
        $result = Db::name("goods")->insert($data);
        return $result;

    }

    public function update()
    {
        //1
//        $data = input("get.");
//        $result = Db::execute("UPDATE goods SET name=:name WHERE id=:id",$data);
//        return $result;
        //2
        $data = input("get.");
        $result = Db::name("goods")->where("id","lt",3)->update($data);
        return $result;

    }

    public function delete()
    {
        //1
//        $data = input("get.");
//        $result = Db::execute("DELETE FROM goods  WHERE id=:id",$data);
//        return $result;
        //2
        $id = input("get.id");
        $result = Db::name("goods")->where("id",$id)->delete();
        return $result;


    }

    public function show()
    {
        //1
//        $result = Db::query("SELECT * FROM goods");
//        return json($result);
        //2
//        $result = Db::name("goods")->where("id&type","1")->value("name");
//        return $result;





        $result = Db::name('goods')
            ->where([
                'id'   => ['between', '5,6']
            ])->select();
        dump($result);
    }
}